<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>分布式事务完全指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            padding: 20px;
            overflow-x: auto;
            font-family: 'Consolas', 'Monaco', monospace;
            font-size: 14px;
            line-height: 1.6;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 12px;
            color: white;
            font-size: 24px;
            margin-bottom: 16px;
        }
        
        .timeline-item {
            position: relative;
            padding-left: 40px;
            padding-bottom: 30px;
        }
        
        .timeline-item::before {
            content: '';
            position: absolute;
            left: 10px;
            top: 0;
            bottom: 0;
            width: 2px;
            background: #e5e7eb;
        }
        
        .timeline-item::after {
            content: '';
            position: absolute;
            left: 6px;
            top: 8px;
            width: 10px;
            height: 10px;
            background: #667eea;
            border-radius: 50%;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 30px 0;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 20px 30px;
            border-radius: 12px;
            margin: 20px 0;
            font-weight: 500;
        }
        
        .concept-card {
            background: #f8f9fa;
            border-left: 4px solid #667eea;
            padding: 20px;
            margin: 20px 0;
            border-radius: 0 8px 8px 0;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fade-in {
            animation: fadeInUp 0.6s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center animate-fade-in">
                <h1 class="text-5xl font-bold mb-6">分布式事务完全指南</h1>
                <p class="text-xl opacity-90 mb-8">从理论到实践，深入理解微服务架构下的事务处理</p>
                <div class="flex justify-center space-x-6">
                    <div class="text-center">
                        <i class="fas fa-network-wired text-3xl mb-2"></i>
                        <p class="text-sm">分布式理论</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-cogs text-3xl mb-2"></i>
                        <p class="text-sm">解决方案</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-code text-3xl mb-2"></i>
                        <p class="text-sm">实战应用</p>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <!-- 事务基础概念 -->
        <div class="content-card rounded-xl shadow-lg p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title">事务基础概念</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div>
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">什么是事务？</h3>
                    <p class="text-gray-600 leading-relaxed">
                        事务是应用程序中一系列严密的操作，所有操作必须成功完成，否则在每个操作中所作的所有更改都会被撤消。事务具有原子性，一个事务中的一系列的操作要么全部成功，要么一个都不做。
                    </p>
                </div>
                
                <div>
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">ACID特性</h3>
                    <div class="space-y-3">
                        <div class="flex items-start">
                            <span class="text-purple-600 font-bold mr-2">A</span>
                            <div>
                                <strong>原子性（Atomicity）</strong>
                                <p class="text-sm text-gray-600">所有操作要么全部完成，要么全部不做</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <span class="text-purple-600 font-bold mr-2">C</span>
                            <div>
                                <strong>一致性（Consistency）</strong>
                                <p class="text-sm text-gray-600">事务执行必须保证系统的一致性</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <span class="text-purple-600 font-bold mr-2">I</span>
                            <div>
                                <strong>隔离性（Isolation）</strong>
                                <p class="text-sm text-gray-600">事务之间不会互相影响</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <span class="text-purple-600 font-bold mr-2">D</span>
                            <div>
                                <strong>持久性（Durability）</strong>
                                <p class="text-sm text-gray-600">事务完成后数据永久保存</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 架构对比图 -->
            <div class="mermaid">
                graph LR
                    subgraph "单体架构"
                        A[应用服务] --> B[本地事务]
                        B --> C[单一数据库]
                    end
                    
                    subgraph "微服务架构"
                        D[服务A] --> E[数据库A]
                        F[服务B] --> G[数据库B]
                        H[服务C] --> I[数据库C]
                        D -.分布式事务.-> F
                        F -.分布式事务.-> H
                    end
                    
                    style A fill:#667eea,stroke:#fff,color:#fff
                    style D fill:#f093fb,stroke:#fff,color:#fff
                    style F fill:#f093fb,stroke:#fff,color:#fff
                    style H fill:#f093fb,stroke:#fff,color:#fff
            </div>
        </div>

        <!-- 分布式事务概念 -->
        <div class="content-card rounded-xl shadow-lg p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title">分布式事务的挑战</h2>
            
            <div class="highlight-box">
                <i class="fas fa-exclamation-triangle mr-2"></i>
                在微服务架构中，由于会将不同的业务拆分到不同的微服务实例之中，这样就会彻底丧失传统数据库事务的支持，不同的微服务之间没有事务上的联系，一旦出现错误就可能违反ACID原则。
            </div>

            <div class="grid md:grid-cols-3 gap-6 mt-8">
                <div class="text-center">
                    <div class="feature-icon mx-auto">
                        <i class="fas fa-database"></i>
                    </div>
                    <h4 class="font-semibold mb-2">分库分表</h4>
                    <p class="text-sm text-gray-600">数据分散在不同数据库实例</p>
                </div>
                <div class="text-center">
                    <div class="feature-icon mx-auto">
                        <i class="fas fa-server"></i>
                    </div>
                    <h4 class="font-semibold mb-2">微服务架构</h4>
                    <p class="text-sm text-gray-600">服务独立部署，独立数据库</p>
                </div>
                <div class="text-center">
                    <div class="feature-icon mx-auto">
                        <i class="fas fa-sync-alt"></i>
                    </div>
                    <h4 class="font-semibold mb-2">数据一致性</h4>
                    <p class="text-sm text-gray-600">保证跨服务的数据一致</p>
                </div>
            </div>
        </div>

        <!-- 分布式理论 -->
        <div class="content-card rounded-xl shadow-lg p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title">分布式理论基础</h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <h3 class="text-2xl font-semibold mb-4 text-purple-600">CAP理论</h3>
                    <div class="concept-card">
                        <div class="space-y-3">
                            <div>
                                <strong class="text-purple-600">C - Consistency（一致性）</strong>
                                <p class="text-sm text-gray-600 mt-1">数据的强一致性，所有节点同时看到相同的数据</p>
                            </div>
                            <div>
                                <strong class="text-purple-600">A - Availability（可用性）</strong>
                                <p class="text-sm text-gray-600 mt-1">每个请求都能获得符合预期的响应</p>
                            </div>
                            <div>
                                <strong class="text-purple-600">P - Partition tolerance（分区容错性）</strong>
                                <p class="text-sm text-gray-600 mt-1">系统在网络分区时仍能正常服务</p>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div>
                    <h3 class="text-2xl font-semibold mb-4 text-purple-600">BASE理论</h3>
                    <div class="concept-card">
                        <div class="space-y-3">
                            <div>
                                <strong class="text-purple-600">BA - Basically Available（基本可用）</strong>
                                <p class="text-sm text-gray-600 mt-1">允许牺牲部分功能保证核心功能可用</p>
                            </div>
                            <div>
                                <strong class="text-purple-600">S - Soft state（软状态）</strong>
                                <p class="text-sm text-gray-600 mt-1">允许数据存在中间状态</p>
                            </div>
                            <div>
                                <strong class="text-purple-600">E - Eventually consistent（最终一致性）</strong>
                                <p class="text-sm text-gray-600 mt-1">数据最终会达到一致状态</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="mermaid mt-8">
                graph TB
                    subgraph "CAP三角"
                        C[一致性]
                        A[可用性]
                        P[分区容错性]
                        C -.CP系统.-> P
                        A -.AP系统.-> P
                        C -.CA系统.-> A
                    end
                    
                    style C fill:#667eea,stroke:#fff,color:#fff
                    style A fill:#f093fb,stroke:#fff,color:#fff